package com.shoppingmall.activity.mine;

import android.os.Bundle;
import android.view.View;

import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.base.BaseFragment;
import com.example.zyh.toolslib.widget.TitleBar;
import com.google.android.material.tabs.TabLayout;
import com.shoppingmall.R;
import com.shoppingmall.fragment.DealerConsumeCoinsDetailsFragment;
import com.shoppingmall.fragment.DealerSubordinateDealersDetailsFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 2020/3/15
 * 描述：我的经销商明细
 */
public class MineDealersDetailsActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private List<BaseFragment> fragmentList;
    private String [] title = {"重消币明细","经销商明细"};

    @Override
    protected int initLayout() {
        return R.layout.activity_mine_dealer_details;
    }


    @Override
    protected void initView() {

        fragmentList = new ArrayList<>();
        fragmentList.add(new DealerConsumeCoinsDetailsFragment());
        fragmentList.add(new DealerSubordinateDealersDetailsFragment());
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setOffscreenPageLimit(2);
        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }
}
